"""
更新所有简历的完成度
"""
from django.core.management.base import BaseCommand
from resume_management.models import Resume


class Command(BaseCommand):
    help = '更新所有简历的完成度'

    def handle(self, *args, **options):
        resumes = Resume.objects.all()
        updated_count = 0
        
        for resume in resumes:
            old_rate = resume.completion_rate
            new_rate = resume.calculate_actual_completion_rate()
            
            if old_rate != new_rate:
                updated_count += 1
                self.stdout.write(
                    f'简历 {resume.id} ({resume.title}) 完成度从 {old_rate}% 更新为 {new_rate}%'
                )
        
        self.stdout.write(
            self.style.SUCCESS(f'成功更新了 {updated_count} 个简历的完成度')
        )
